package com.itqianfeng.smartmeeting.config;

import com.alibaba.fastjson2.JSON;
import com.itqianfeng.smartmeeting.util.CommonResult;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        Map map = CommonResult.ok( "注销成功" , authentication.getPrincipal());
        String s = JSON.toJSONString(map);
        httpServletResponse.setContentType("application/json;charset=utf-8");
        //后端向前端发送数据
        httpServletResponse.getWriter().write(s);
    }
}
